/**
 * 我的位置组件
 */
import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  TouchableOpacity
} from 'react-native';
import { px2dp } from 'rn-xiaobu-utils';
import flexStyle from '../../../configs/flex';
import Icon from '../../public/icon';
import { iconDefaultColor } from '../../../configs/skin';
import NavigationService from '../../../utils/NavigationService';
import { getCurrentPosition } from '../../../../plugins/location';

export default class MyPosition extends Component {
  static defaultProps = {
    itemOnPress: () => {
    }
  }

  /**
   * 组件点击方法
   */
  onPress = () => {
    // 获取当前位置
    getCurrentPosition().then(res=>{
      NavigationService.back()
      this.props.itemOnPress(res)
    })
  }

  render () {
    return (
      <TouchableOpacity style={[flexStyle.flexH, flexStyle.flexHc, flexStyle.flexVc, styles.container]}
        onPress={this.onPress}>
        <Text style={{ color: iconDefaultColor }}><Icon name={'mypoint'} size={30}/>&nbsp;我的位置</Text>
      </TouchableOpacity>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    width: '100%',
    height: px2dp(100),
    backgroundColor: '#ffffff'
  }
});